home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / EditorKit.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  191 lines

  1. /*
  2.  * @(#)EditorKit.java    1.8 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.io.*;
  23. import com.sun.java.swing.Action;
  24. import com.sun.java.swing.JEditorPane;
  25.  
  26. /**
  27.  * Establishes the set of things needed by a text component
  28.  * to be a reasonably functioning editor for some <em>type</em>
  29.  * of text content.  The EditorKit acts as a factory for some
  30.  * kind of policy.  For example, an implementation 
  31.  * of html and rtf can be provided that is replaceable 
  32.  * with other implementations.
  33.  * <p>
  34.  * A kit can safely store editing state as an instance
  35.  * of the kit will be dedicated to a text component.
  36.  * New kits will normally be created by cloning a 
  37.  * prototype kit.  The kit will have it's 
  38.  * <code>setComponent</code> method called to establish
  39.  * it's relationship with a JTextComponent.
  40.  *
  41.  * @author  Timothy Prinzing
  42.  * @version 1.8 04/09/98
  43.  */
  44. public abstract class EditorKit implements Cloneable, Serializable {
  45.  
  46.     /**
  47.      * Creates a copy of the editor kit.  This
  48.      * allows an implementation to serve as a prototype
  49.      * for others, so that they can be quickly created.
  50.      *
  51.      * @return the copy
  52.      */
  53.     public abstract Object clone();
  54.  
  55.     /**
  56.      * Called when the kit is being installed into the
  57.      * a JEditorPane.  
  58.      *
  59.      * @param c the JEditorPane
  60.      */
  61.     public void install(JEditorPane c) {
  62.     }
  63.  
  64.     /**
  65.      * Called when the kit is being removed from the
  66.      * JEditorPane.  This is used to unregister any 
  67.      * listeners that were attached.
  68.      *
  69.      * @param c the JEditorPane
  70.      */
  71.     public void deinstall(JEditorPane c) {
  72.     }
  73.  
  74.     /**
  75.      * Gets the MIME type of the data that this
  76.      * kit represents support for.
  77.      *
  78.      * @return the type
  79.      */
  80.     public abstract String getContentType();
  81.  
  82.     /**
  83.      * Fetches a factory that is suitable for producing 
  84.      * views of any models that are produced by this
  85.      * kit.  
  86.      *
  87.      * @return the factory
  88.      */
  89.     public abstract ViewFactory getViewFactory();
  90.  
  91.     /**
  92.      * Fetches the set of commands that can be used
  93.      * on a text component that is using a model and
  94.      * view produced by this kit.
  95.      *
  96.      * @return the set of actions
  97.      */ 
  98.     public abstract Action[] getActions();
  99.  
  100.     /**
  101.      * Fetches a caret that can navigate through views
  102.      * produced by the associated ViewFactory.
  103.      *
  104.      * @return the caret
  105.      */
  106.     public abstract Caret createCaret();
  107.  
  108.     /**
  109.      * Creates an uninitialized text storage model
  110.      * that is appropriate for this type of editor.
  111.      *
  112.      * @return the model
  113.      */
  114.     public abstract Document createDefaultDocument();
  115.  
  116.     /**
  117.      * Inserts content from the given stream which is expected 
  118.      * to be in a format appropriate for this kind of content
  119.      * handler.
  120.      * 
  121.      * @param in  The stream to read from
  122.      * @param doc The destination for the insertion.
  123.      * @param pos The location in the document to place the
  124.      *   content >= 0.
  125.      * @exception IOException on any I/O error
  126.      * @exception BadLocationException if pos represents an invalid
  127.      *   location within the document.
  128.      */
  129.     public abstract void read(InputStream in, Document doc, int pos) 
  130.     throws IOException, BadLocationException;
  131.  
  132.     /**
  133.      * Writes content from a document to the given stream
  134.      * in a format appropriate for this kind of content handler.
  135.      * 
  136.      * @param out  The stream to write to
  137.      * @param doc The source for the write.
  138.      * @param pos The location in the document to fetch the
  139.      *   content from >= 0.
  140.      * @param len The amount to write out >= 0.
  141.      * @exception IOException on any I/O error
  142.      * @exception BadLocationException if pos represents an invalid
  143.      *   location within the document.
  144.      */
  145.     public abstract void write(OutputStream out, Document doc, int pos, int len) 
  146.     throws IOException, BadLocationException;
  147.  
  148.     /**
  149.      * Inserts content from the given stream which is expected 
  150.      * to be in a format appropriate for this kind of content
  151.      * handler.
  152.      * <p>
  153.      * Since actual text editing is unicode based, this would 
  154.      * generally be the preferred way to read in the data.  
  155.      * Some types of content are stored in an 8-bit form however,
  156.      * and will favor the InputStream.
  157.      * 
  158.      * @param in  The stream to read from
  159.      * @param doc The destination for the insertion.
  160.      * @param pos The location in the document to place the
  161.      *   content >= 0.
  162.      * @exception IOException on any I/O error
  163.      * @exception BadLocationException if pos represents an invalid
  164.      *   location within the document.
  165.      */
  166.     public abstract void read(Reader in, Document doc, int pos) 
  167.     throws IOException, BadLocationException;
  168.  
  169.     /**
  170.      * Writes content from a document to the given stream
  171.      * in a format appropriate for this kind of content handler.
  172.      * <p>
  173.      * Since actual text editing is unicode based, this would 
  174.      * generally be the preferred way to write the data.  
  175.      * Some types of content are stored in an 8-bit form however,
  176.      * and will favor the OutputStream.
  177.      * 
  178.      * @param out  The stream to write to
  179.      * @param doc The source for the write.
  180.      * @param pos The location in the document to fetch the
  181.      *   content >= 0.
  182.      * @param len The amount to write out >= 0.
  183.      * @exception IOException on any I/O error
  184.      * @exception BadLocationException if pos represents an invalid
  185.      *   location within the document.
  186.      */
  187.     public abstract void write(Writer out, Document doc, int pos, int len) 
  188.     throws IOException, BadLocationException;
  189.  
  190. }
  191.